package io.kimmking.kmq.core;

import lombok.SneakyThrows;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;

public final class Kmq {

    private final String topic;
    private final Queue queue;

    public Kmq(String topic, int capacity) {
        this.topic = topic;
        this.queue = new Queue(capacity);
    }


    public boolean send(KmqMessage message) {
        return queue.offer(message);
    }

    @SneakyThrows
    public KmqMessage poll(long timeout) {
        return queue.poll(timeout, TimeUnit.MILLISECONDS);
    }


    public String getTopic() {
        return topic;
    }

    public Queue getQueue() {
        return queue;
    }
}
